﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Microsoft.Practices.Unity;

namespace CodeContrib.Web.Mvc.Unity
{
	public class UnityDependencyResolver : IDependencyResolver
	{
		private readonly IUnityContainer _container;

		public UnityDependencyResolver(IUnityContainer container)
		{
			_container = container;
		}

		public object GetService(Type serviceType)
		{
			try
			{
				return _container.Resolve(serviceType);
			}
			catch
			{
				return null;
			}
		}

		public IEnumerable<object> GetServices(Type serviceType)
		{
			try
			{
				return _container.ResolveAll(serviceType);
			}
			catch
			{
				return new List<object>();
			}
		}
	}
}